{extend name='common/_container'}
{block name="content"}
<div class="ibox float-e-margins">
	<div class="ibox-content">
		<div class="form-horizontal" id="CodeInfoForm">
			<div class="row">
				<div class="col-sm-12">
				<!-- form start -->
					<div class="form-group">
						<label class="col-sm-2 control-label">标题：</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" id="title" value="" name="title" class="form-control" placeholder="请输入标题">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">简介：</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" id="subtitle" value="" name="subtitle" class="form-control" placeholder="请输入简介">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">活动开始时间：</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" value="{:date('Y-m-d H:i:s')}" name="start_time"  placeholder="请输入活动开始时间" class="form-control" id="start_time">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">报名开始时间：</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" value="{:date('Y-m-d H:i:s')}" name="sign_up_start_time"  placeholder="请输入报名开始时间" class="form-control" id="sign_up_start_time">
						</div>
					</div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">报名结束时间：</label>
                        <div class="col-sm-9">
                            <input type="text" autocomplete="off" value="{:date('Y-m-d H:i:s')}" name="sign_up_end_time"  placeholder="请输入报名结束时间" class="form-control" id="sign_up_end_time">
                        </div>
                    </div>
					<div class="form-group">
						<label class="col-sm-2 control-label">地址：</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" id="address" value="" name="address" class="form-control" placeholder="请输入地址">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">经纬度：</label>
						<div class="col-sm-9">
							<div class="input-group" id="coordinate_address">
							<textarea id="coordinate" name="coordinate"  class="form-control" placeholder="请输入经纬度">{$info.coordinate}</textarea>
								<span class="input-group-addon"><span class="glyphicon glyphicon-map-marker"></span></span>
							</div>
						</div>
					</div>
					<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.3&key=ed1fafa0307bb4991da41f54d8a88b46"></script>
					<script src="__PUBLIC__/static/js/plugins/map/bootstrap.AMapPositionPicker.js"></script>

					<script type="text/javascript">
					$(function () {
						var p = $("#coordinate_address").AMapPositionPicker();

					});
					</script>
					<div class="form-group">
						<label class="col-sm-2 control-label">活动详情：</label>
						<div class="col-sm-9">
							<script id="content" type="text/plain" name="content" style="width:100%;height:300px;"></script>
							<script type="text/javascript">
								var ue = UE.getEditor('content',{serverUrl : '{:url("backend/Upload/uploadUeditor")}'});
								scaleEnabled:true
							</script>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">活动封面图：</label>
						<div class="col-sm-6">
							<div class="images pic_list">
								<li id="images_upload"></li>
							</div>
							<div style="clear:both"></div>
							<span class="help-block m-b-none images_process"></span>
						</div>
					</div>
					<div class="form-group layui-form">
						<label class="col-sm-2 control-label">是否收费：</label>
						<div class="col-sm-9">
							<?php if(!isset($info['is_charge'])){ $info['is_charge'] = '0'; }; ?>
							<input name="is_charge" value="1" type="radio" {if condition="$info.is_charge eq '1'"}checked{/if} title="是">
							<input name="is_charge" value="0" type="radio" {if condition="$info.is_charge eq '0'"}checked{/if} title="否">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">报名费用：</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" id="sign_up_price" value="" name="sign_up_price" class="form-control" placeholder="请输入报名费用">
						</div>
					</div>
					<div class="form-group layui-form">
						<label class="col-sm-2 control-label">活动状态：</label>
						<div class="col-sm-9">
							<?php if(!isset($info['status'])){ $info['status'] = 0; }; ?>
							<input name="status" value="1" type="radio" {if condition="$info.status eq '1'"}checked{/if} title="开启">
							<input name="status" value="0" type="radio" {if condition="$info.status eq '0'"}checked{/if} title="关闭">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">活动人数：</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" id="activity_num" value="" name="activity_num" class="form-control" placeholder="请输入活动人数">
						</div>
					</div>

				<!-- form end -->
				</div>
			</div>
			<div class="hr-line-dashed"></div>
			<div class="row btn-group-m-t">
				<div class="col-sm-9 col-sm-offset-1">
					<button type="button" class="btn btn-primary" onclick="CodeInfoDlg.add()" id="ensure">
						<i class="fa fa-check"></i>&nbsp;确认提交
					</button>
					<button type="button" class="btn btn-danger" onclick="CodeInfoDlg.close()" id="cancel">
						<i class="fa fa-eraser"></i>&nbsp;取消
					</button>
				</div>
			</div>
		</div>
	</div>
</div>
<script src="__PUBLIC__/static/js/upload.js" charset="utf-8"></script>
<script src="__PUBLIC__/static/js/plugins/layui/layui.js" charset="utf-8"></script>
<script src='__PUBLIC__/static/js/plugins/paixu/jquery-migrate-1.1.1.js'></script>
<script src='__PUBLIC__/static/js/plugins/paixu/jquery.dragsort-0.5.1.min.js'></script>
<script>
$(function(){
	$(".filelist").dragsort({dragSelector: "img",dragBetween: true ,dragEnd:function(){}});
});
layui.use(['form'],function(){});
uploader('images_upload','images','image',true,'{$info.images}','{:getUploadServerUrl()}');
setUploadButton('images_upload');
laydate.render({elem: '#start_time',type: 'datetime',trigger:'click'});
laydate.render({elem: '#sign_up_start_time',type: 'datetime',trigger:'click'});
laydate.render({elem: '#createtime',type: 'datetime',trigger:'click'});
laydate.render({elem: '#sign_up_end_time',type: 'datetime',trigger:'click'});
var CodeInfoDlg = {
	CodeInfoData: {},
	validateFields: {
		title: {
			validators: {
				notEmpty: {
					message: '标题不能为空'
	 			},
	 		}
	 	},
		subtitle: {
			validators: {
				notEmpty: {
					message: '简介不能为空'
	 			},
	 		}
	 	},
		start_time: {
			validators: {
				notEmpty: {
					message: '活动开始时间不能为空'
	 			},
	 		}
	 	},
		address: {
			validators: {
				notEmpty: {
					message: '地址不能为空'
	 			},
	 		}
	 	},
		content: {
			validators: {
				notEmpty: {
					message: '活动详情不能为空'
	 			},
	 		}
	 	},
	 }
}

CodeInfoDlg.collectData = function () {
	this.set('activity_id').set('title').set('subtitle').set('start_time').set('sign_up_start_time').set('address').set('coordinate').set('sign_up_price').set('wxapp_id').set('createtime').set('activity_num').set('sign_up_end_time');
};

CodeInfoDlg.add = function () {
	 this.clearData();
	 this.collectData();
	 if (!this.validate()) {
	 	return;
	 }
	 var content = UE.getEditor('content').getContent();
	 var images = {};
	 $(".images li").each(function() {
		if($(this).find('img').attr('src')){
	 		images[$(this).index()] = {'url':$(this).find('img').attr('src'),'title':$(this).find('input').val()};
		}
	 });
	 var is_charge = $("input[name = 'is_charge']:checked").val();
	 var status = $("input[name = 'status']:checked").val();
	 var ajax = new $ax(Feng.ctxPath + "/ZhActivity/add", function (data) {
	 	if ('00' === data.status) {
	 		Feng.success(data.msg,1000);
	 		window.parent.CodeGoods.table.refresh();
	 		CodeInfoDlg.close();
	 	} else {
	 		Feng.error(data.msg + "！",1000);
		 }
	 })
	 ajax.set('content',content);
	 ajax.set('images',(JSON.stringify(images) == '{}' || JSON.stringify(images) == '{"":""}') ? '' : JSON.stringify(images));
	 ajax.set('is_charge',is_charge);
	 ajax.set('status',status);
	 ajax.set(this.CodeInfoData);
	 ajax.start();
};


</script>
<script src="__PUBLIC__/static/js/base.js" charset="utf-8"></script>
{/block}
